package com.speech.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.ontbee.legacyforks.cn.pedant.SweetAlert.SweetAlertDialog;
import com.speech.R;
import com.speech.activity.InviteActivity;
import com.speech.activity.MissionNoobActivity;
import com.speech.activity.MissionSuperActivity;
import com.speech.net.BasicCallBack;
//import com.speech.net.HttpCommunicationManager;
import com.speech.net.constant.EnumReqestActionCode;
import com.speech.net.entity.MessageC2S;
import com.speech.net.entity.MessageC2SBuilder;
import com.speech.net.entity.MessageS2C;
import com.speech.utils.ClipBoardUtil;
import com.speech.utils.JsonProcessor;

import org.w3c.dom.Text;

public class MissionFragment extends Fragment {

    private TextView tv_entrance_noob;
    private TextView tv_entrance_super;
    private TextView tv_entrance_invite;

    private ImageView img_invite;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_mission, null);

        _initView(view);

        img_invite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ClipBoardUtil.strInviteCode == null) {
                    _get_invite_code();
                } else {
                    ClipBoardUtil.copy("", getActivity());
                    Toast.makeText(getActivity(),"已将邀请码保存到剪切板",Toast.LENGTH_SHORT).show();
//                    new SweetAlertDialog(getActivity(), SweetAlertDialog.SUCCESS_TYPE)
//                            .setTitleText("已将邀请码保存到剪切板")
//                            .setConfirmText("OK")
//                            .show();
                }
            }
        });

        tv_entrance_invite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), InviteActivity.class));
            }
        });

        tv_entrance_noob.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), MissionNoobActivity.class));
            }
        });

        tv_entrance_super.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), MissionSuperActivity.class));
            }
        });

        return view;
    }

    private void _initView(View view) {
        tv_entrance_noob = view.findViewById(R.id.tv_mission_noob_entrance);
        tv_entrance_super = view.findViewById(R.id.tv_mission_super_entrance);
        tv_entrance_invite = view.findViewById(R.id.tv_mission_invite_entrance);

        img_invite = view.findViewById(R.id.img_mission_invite);
    }

    private void _get_invite_code() {
        //TODO: 接口请求
//        MessageC2S msg_c2s = MessageC2SBuilder.buildGeneral_MessageC2S(getActivity(), EnumReqestActionCode.获得邀请码地址, null);
//        String json = JsonProcessor.StcGetJson(msg_c2s);
//        HttpCommunicationManager.getInstance().doPost(json, new BasicCallBack(getActivity(), json, new BasicCallBack.BasicCallBackListener() {
//            @Override
//            public void success(MessageS2C msg_s2c) {
//                ClipBoardUtil.strInviteCode = msg_s2c.strData.replace("{\"url\":\"", "").replace("\"}", "");
//                ClipBoardUtil.copy("", getActivity());
//                Toast.makeText(getActivity(),"已将邀请码保存到剪切板",Toast.LENGTH_SHORT).show();
////                new SweetAlertDialog(getActivity(), SweetAlertDialog.SUCCESS_TYPE)
////                        .setTitleText("已将邀请码保存到剪切板")
////                        .setConfirmText("OK")
////                        .show();
//            }
//            @Override
//            public void fail(MessageS2C msg_s2c) {
//                ClipBoardUtil.copy(null, getActivity());
//                Toast.makeText(getActivity(),"已将邀请码保存到剪切板",Toast.LENGTH_SHORT).show();
////                new SweetAlertDialog(getActivity(), SweetAlertDialog.SUCCESS_TYPE)
////                        .setTitleText("已将邀请码保存到剪切板")
////                        .setConfirmText("OK")
////                        .show();
//            }
//        }));
    }

}
